package com.rd.student.jike.class2.lihongming.Slolution3;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @Auther:Heinrich
 * @Date:2023/7/19-07-19-15:40
 * @Description:com.rd.student.jike.class2.lihongming.Solution719
 * @version:1.0
 */
public class Question2_2 {
    public static void main(String[] args) throws InterruptedException {
        sumPrint();
        Thread.sleep(1000);
        System.out.println(AddSum1.sum);
    }
    public static void sumPrint(){
        new AddSum1("con1",1,10).start();
        new AddSum1("con2",11,20).start();
        new AddSum1("con3",21,30).start();
        new AddSum1("con4",31,40).start();
        new AddSum1("con5",41,50).start();
        new AddSum1("con6",51,60).start();
        new AddSum1("con7",61,70).start();
        new AddSum1("con8",71,80).start();
        new AddSum1("con9",81,90).start();
        new AddSum1("con10",91,100).start();
    }
}
class AddSum1 extends Thread{
    int min;
    int max;
    ReentrantLock lock = new ReentrantLock();
    static AtomicInteger sum = new AtomicInteger(0);

    public AddSum1(String name, int min, int max) {
        super(name);
        this.min = min;
        this.max = max;
    }

    @Override
    public void run() {
        for (int i = this.min; i <= this.max; i++) {
            sum.getAndAdd(i);
            //System.out.println(getName() + " " + i + " " + sum);
        }
    }
}